<!--************************************************************ -->
<!--* 文件创建日期：2010                                  * -->
<!--* 文件修改日期：			                                   * -->
<!--************************************************************ -->
<!--JSP初始化设置-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.infomanage.po.*" %>
<%@page import="com.infomanage.vo.*" %>
<%@page import="com.infomanage.enums.*"%>
<%@page import="com.infomanage.util.TimeUtil"%>
<%@page import="com.infomanage.service.worklog.*"%>
<%  response.addDateHeader("Expires", 0);response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache");%>
<%
	request.setCharacterEncoding("UTF-8");
	String itemId = request.getParameter("itemId");
    if(itemId == null) itemId = "";
    
    DutypersonItem item = DutyPersonService.loadDutyperson(request, response, out);
    String beginTime = "";
    String endTime = "";
    int masterPersonId = -1;
    int slavePersonId = -1;
    int attendantPersonId = -1;
    int dispatcherPersonId = -1;
    String masterPersonName = "";
    String slavePersonName = "";
    String attendantPersonName = "";
    String dispatcherPersonName = "";
    if(item != null) {
    	Dutyperson bean = item.getBean();
    	masterPersonId = bean.getMasterPersonId();
    	slavePersonId = bean.getSlavePersonId();
    	attendantPersonId = bean.getAttendantPersonId();
    	dispatcherPersonId = bean.getDispatcherPersonId();
    	Person masterPerson = item.getMasterPerson();
    	Person slavePerson = item.getSlavePerson();
    	Person attendantPerson = item.getAttendantPerson();
    	Person dispatcherPerson = item.getDispatcherPerson();
    	masterPersonName = masterPerson.getName();
    	slavePersonName = slavePerson.getName();
    	attendantPersonName = attendantPerson.getName();
    	dispatcherPersonName = dispatcherPerson.getName();
    	beginTime = bean.getBeginTime();
    	endTime = bean.getEndTime();
    } 
    String defaultBeginTime = DutyPersonService.getLastEndTime(request, response, out);
%>
<html>
<head>
	<title>值班人员</title>
	<META HTTP-EQUIV="Pragma" CONTENT="no-cache">	
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<link href="../../css/calendar.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../../js/calendar.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript">
	   function init() {
		   if("" != "<%=itemId%>") { // 修改
		   	    form1.beginDay.value = "<%=TimeUtil.toDayTime(beginTime)%>";
		   	    form1.beginHour.value = "<%=TimeUtil.toHourTime(beginTime)%>";
		   	    form1.beginMinute.value = "<%=TimeUtil.toMinuteTime(beginTime)%>";
		   	    
		   	    form1.endDay.value = "<%=TimeUtil.toDayTime(endTime)%>";
		   	    form1.endHour.value = "<%=TimeUtil.toHourTime(endTime)%>";
		   	    form1.endMinute.value = "<%=TimeUtil.toMinuteTime(endTime)%>";
		   }else{
				var date = new Date();
				var today = date.pattern("yyyy-MM-dd")
				form1.beginDay.value = today;
				form1.endDay.value = today;
		   }
		   
		   if("<%=defaultBeginTime%>" != ""){
		   		form1.beginDay.value = "<%=TimeUtil.toDayTime(defaultBeginTime)%>";
		   	    form1.beginHour.value = "<%=TimeUtil.toHourTime(defaultBeginTime)%>";
		   	    form1.beginMinute.value = "<%=TimeUtil.toMinuteTime(defaultBeginTime)%>";
		   }
	   }
	   // 提交
	   function doSubmit(){
	   		if(validate()){
	   			return;
	   		}
		   	form1.beginTime.value = form1.beginDay.value + ";" +form1.beginHour.value + ";" +form1.beginMinute.value;
		   	form1.endTime.value = form1.endDay.value + ";" +form1.endHour.value + ";" +form1.endMinute.value;
		 	if("" == "<%=itemId%>") {
		 		form1.actionType.value = "add";
			}else {
		 		form1.actionType.value = "modify";
			}
		 	form1.submit();
	   }

	   function showError(error){
		   alert(error);
	   }

	   function showInfo(info){
		   alert(info);
		   window.returnValue = "ok";
		   window.close();
	   }
	   
   	   function validate(){
	   		if(form1.beginDay.value == ""){
	   			alert("开始时间不能为空！");
	   			return true;
	   		}
	   		if(form1.endDay.value == ""){
	   			alert("结束时间不能为空！");
	   			return true;
	   		}
	   		if(form1.masterPersonId.value == -1){
	   			alert("主官不能为空！");
	   			return true;
	   		}
	   		if(form1.slavePersonId.value == -1){
	   			alert("副官不能为空！");
	   			return true;
	   		}
	   		if(form1.attendantPersonId.value == -1){
	   			alert("值班员不能为空！");
	   			return true;
	   		}
	   		if(form1.dispatcherPersonId.value == -1){
	   			alert("调度员不能为空！");
	   			return true;
	   		}
	   		
	   		if(!compareDate(form1.beginDay.value,form1.beginHour.value,form1.beginMinute.value, form1.endDay.value,form1.endHour.value,form1.endMinute.value)){
	   			alert("开始时间大于结束时间！");
	   			return true;
	   		}
	   		return false;
	   }
	</script>
</head>
<body  rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0" onclick="clickBody();" onload="init();">
	<form name="form1" action="dutyPerson_action.jsp" method="post" target="actionFrame">
	<input type="hidden" name="itemId" value="<%=itemId%>">
	<input type="hidden" name="actionType">
    <input type="hidden" name="beginTime">
    <input type="hidden" name="endTime">
	<table class="dialogTable" cellpadding="0" cellspacing="0">
		<!-- 表头-->
		<tr class="dialogTableHeader">
			<td>值班人员</td>
		</tr>
		<!-- 表数据-->
		<tr class="dialogTableContent">
			<td>
				<!-- 数据项 -->
				<table class="dataTable" style="table-layout: fixed;" border="0">
					<col width="30%">
					<col width="70%">
					<tr>
						<td class="field">
							值班开始时间
						</td>
						<td>
							<input type="text" style="width: 135px;cursor: hand;" name="beginDay" id="beginDay" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('beginDay', 'y-mm-dd');">
							&nbsp;&nbsp;<select name="beginHour">
			   							<%
			   								for(int i = 0; i < TimeUtil.get24Hours().length; i++){
			   							%>
			   							<option value="<%=TimeUtil.get24Hours()[i]%>"><%=TimeUtil.get24Hours()[i]%></option>
			   							<%
			   								}
			   							%>
		   							</select>
		   							时
		   					&nbsp;&nbsp;<select name="beginMinute">
			   							<%
			   								for(int i = 0; i < TimeUtil.get60Minutes().length; i++){
			   							%>
			   							<option value="<%=TimeUtil.get60Minutes()[i]%>"><%=TimeUtil.get60Minutes()[i]%></option>
			   							<%
			   								}
			   							%>
		   							</select>
		   							分
						</td>
					</tr>
					<tr>
						<td class="field">
							值班结束时间
						</td>
						<td>
							<input type="text" style="width: 135px;cursor: hand;" name="endDay" id="endDay" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('endDay', 'y-mm-dd');">
							&nbsp;&nbsp;<select name="endHour">
			   							<%
			   								for(int i = 0; i < TimeUtil.get24Hours().length; i++){
			   							%>
			   							<option value="<%=TimeUtil.get24Hours()[i]%>"><%=TimeUtil.get24Hours()[i]%></option>
			   							<%
			   								}
			   							%>
		   							</select>
		   							时
		   					&nbsp;&nbsp;<select name="endMinute">
			   							<%
			   								for(int i = 0; i < TimeUtil.get60Minutes().length; i++){
			   							%>
			   							<option value="<%=TimeUtil.get60Minutes()[i]%>"><%=TimeUtil.get60Minutes()[i]%></option>
			   							<%
			   								}
			   							%>
		   							</select>
		   							分
						</td>
					</tr>
					<tr style="height:50px">
						<td class="field">
							主官
						</td>
						<td>
							<span class="treeSpan2" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true"><input class="singleBorder" value="<%=masterPersonName %>" style="width: 300px;text-align:center;" readonly="readonly" treeSelect="true"><input name="masterPersonId" value="<%=masterPersonId %>" type="hidden"></span>
						</td>
					</tr>
					<tr style="height:50px">
						<td class="field" >
							副官
						</td>
						<td>
							<span class="treeSpan2" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true"><input 
									class="singleBorder" value="<%= slavePersonName%>" style="width: 300px;text-align:center;" readonly="readonly" treeSelect="true"><input name="slavePersonId" value="<%=slavePersonId %>" type="hidden"></span>
							
						</td>
					</tr>
					<tr style="height:50px">
						<td class="field">
							值班员
						</td>
						<td>
							<span class="treeSpan2" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true"><input class="singleBorder" name="attendantPersonName" value="<%=attendantPersonName %>" style="width: 300px;text-align:center;" readonly="readonly" treeSelect="true"><input name="attendantPersonId"  value="<%=attendantPersonId %>" type="hidden"></span>
						</td>
					</tr>
					<tr style="height:50px">
						<td class="field">
							调度员
						</td>
						<td>
							<span class="treeSpan2" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true"><input class="singleBorder" name="dispatcherPersonName" value="<%=dispatcherPersonName %>"  style="width: 300px;text-align:center;" readonly="readonly" treeSelect="true"><input name="dispatcherPersonId" value="<%=dispatcherPersonId %>" type="hidden"></span>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="tableBtn">
				<span onclick="doSubmit();">确定</span>
				<span onclick="window.close();">取消</span>
			</td>
		</tr>
		<tr valign="top">
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
	</table>
	</form>
	<iframe src="#" frameborder="0" id="treeFrame" name="frame" style="display: none;position: absolute;"></iframe>
	<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</body>
</html>